package ru.nsu.ccfit.kalah.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import ru.nsu.ccfit.kalah.R;


public class GameSettingsActivity extends Activity {
    EditText firstPlayerName;
    EditText secondPlayerName;
    RadioGroup radioGroup;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_game_settings);

        firstPlayerName = (EditText) findViewById(R.id.first_player_name);
        secondPlayerName = (EditText) findViewById(R.id.second_player_name);
        radioGroup = (RadioGroup) findViewById(R.id.radiogroup);
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                switch (radioGroup.getCheckedRadioButtonId()) {
                    case R.id.radio_one_player:
                        secondPlayerName.setVisibility(View.INVISIBLE);
                        secondPlayerName.setText("AI Player", null);
                        break;
                    case R.id.radio_two_players:
                        secondPlayerName.setVisibility(View.VISIBLE);
                        secondPlayerName.setText("", null);
                        break;
                }
            }
        });
    }

    public void onClickApply(View view) {
        if (firstPlayerName.getText().length() == 0 || secondPlayerName.getText().length() == 0) {
            Toast.makeText(this, "Please fill all fields!", Toast.LENGTH_SHORT).show();

            return;
        }

        Intent intent = new Intent(this, GameActivity.class);
        intent.putExtra(GameActivity.EXTRA_FIRST_PLAYER_NAME, firstPlayerName.getText().toString());
        intent.putExtra(GameActivity.EXTRA_SECOND_PLAYER_NAME, secondPlayerName.getText().toString());
        intent.putExtra(GameActivity.EXTRA_TWO_PLAYERS_FLAG, radioGroup.getCheckedRadioButtonId() == R.id.radio_two_players);
        startActivity(intent);
        finish();
    }
}